package dorm_admin_sys;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.control.PasswordField;
import javafx.scene.layout.GridPane;//网格面板
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.Button;
import javafx.stage.StageStyle;


import java.awt.*;

public class register extends Application {
    final Label lbl_user=new Label("用户名：");
    final Label lbl_passwd=new Label(" 密码：");
    final PasswordField pwf_passwd=new PasswordField();
    final TextField tf_user=new TextField();
    static boolean isJump=false;

    @Override
    public void start(Stage register_primaryStage){
        GridPane registerPane=new GridPane();
        registerPane.setPadding(new Insets(10,8,10,8));
        registerPane.setHgap(5);
        registerPane.setVgap(5);
        tf_user.setPromptText("输入用户名");
        registerPane.add(lbl_user,0,0);
        registerPane.add(tf_user,1,0);
        pwf_passwd.setPromptText("输入密码：");
        registerPane.add(lbl_passwd,0,1);
        registerPane.add(pwf_passwd,1,1);
        Button bt_register=new Button("登录");
        Button bt_cancel=new Button("取消");
        registerPane.add(bt_cancel,0,2);
        registerPane.add(bt_register,1,2);

        //设置登录按钮的动作事件
        bt_register.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                String user_text=tf_user.getText();
                String passwd_text=pwf_passwd.getText();
                System.out.println(user_text+"  "+passwd_text);
                try{ isJump=new register_sql().resultRegisterSqlStatus(user_text,passwd_text); }
                catch (ClassNotFoundException classNotFound){
                    System.out.println(classNotFound.getStackTrace());
                }
                if (isJump=true)
                    System.out.println("登录成功，开始跳转页面！");
                else
                    System.out.println("登录失败");
            }
        });

        Scene scene=new Scene(registerPane,400,120);
        register_primaryStage.setTitle("登录");
        register_primaryStage.setScene(scene);
        register_primaryStage.show();
    }

}
